define(["cmn"],function(cmn){
	var ejs=cmn.ejs("19911204/0");
	ejs.set("main","main");
	ejs.set("msglist","msglist");
	ejs.set("newest","newest");

	return {
		init:function(){
			var _=this;
			_.renderMain();
		},
		renderMain:function(){
			var _=this;
			_.el.html(ejs.main,function(){
				_.el.find("#revew1022").on("click",sendmsg);
				_.el.find("#revew_countent_1022").on("keyup",function(e){
					if(e.keyCode==13)sendmsg();
				});
				msgloop();
				_.el.find("#refresh1022").on("click",newest);
				newest();
			});

			//消息循环
			function msgloop(){

				var div = _.el.find("#msglist1022");
				if(div.size()>0){
					_.renderMsgList(div);
					setTimeout(msgloop,1000*5);
				}
			}
			//发送消息
			function sendmsg(){
				if(!_.el.find("#form1022").validate())return;
				cmn.post({
					action:"User_sendmsg",
					params:{
						msg:_.el.find("#revew_countent_1022").val()
					}
				}).then(function(data){
					if(data instanceof Array)data.reverse();
					_.el.find("#msglist1022").html(ejs.msglist,{list:data});
					_.el.find("#form1022").reset();
				});
			}
			//最新列表
			function newest(){
				cmn.lbox.show();
				cmn.post({
					action:"Blog_newest",
					params:{
						currentIndex:0,
						pageSize:5
					}
				}).then(function(data){
					cmn.lbox.hide();
					_.el.find("#bloglist1022").html(ejs.newest,{list:data});
				});
			}

		},
		renderMsgList:function(div){
			var _=this;
			cmn.post({
				action:"User_msglist"
			}).then(function(data){
				if(data instanceof Array)data.reverse();
				div.html(ejs.msglist,{list:data});
			});
		}
	}
});